import BaseInput from './BaseInput'
import { getUserPhone } from '../../../../src/utils/UserBean'

export default class PhoneInput extends BaseInput {
  constructor (props) {
    super(props)

    this.state = {
      icon: require('../../../../assets/img/login/phone.png'),
      placeholder: '请输入手机号',
      keyboardType: 'numeric',
      isSecure: false,
      showEye: false,
      showDelete: 'none',
      value: ''
    }

    getUserPhone().then(phone => {
      this._inputValueChange(phone)
      // this.setState({ value: phone })
    })
  }

  _validText = () => {
    let text = this.state.value
    return new Promise((resolve, reject) => {
      if (text.length === 0) {
        reject(new Error('手机号不能为空'))
      } else if (!/^1\d{10}$/.test(text)) {
        reject(new Error('手机号格式不正确'))
      } else {
        resolve(text)
      }
    })
  }
}
